<?
 include("../header.php");
 include("../lib/config.php");
 	$nik 		= $HTTP_POST_VARS['nik'];
 	$periode 	= $HTTP_POST_VARS['periode'];
	//$show 	= $HTTP_GET_VARS['show'];
	$nikg		= $HTTP_GET_VARS['nik'];
	$nama		= $HTTP_GET_VARS['nama'];
	$no			= $HTTP_GET_VARS['no'];
	$no_res		= $HTTP_GET_VARS['no_res'];
	$op			= $HTTP_GET_VARS['op'];
	$st			= $HTTP_GET_VARS['st']; // approval
	
	if($op == "edit"){
		$Faction = "../lib/update.php";
		$Vbutton = "Update";
		$sql = mssql_query("SELECT CONVERT(CHAR(12), tgl_kwitansi, 103) TglKwitansi, CONVERT(CHAR(12), tanggal, 103) tgl_restitusi, CONVERT(CHAR(12), tgl_bayar, 103) TglBayar, * FROM VMedical WHERE NIK='$nikg' AND nomor='$no_res'",$conn);
		$row = mssql_fetch_array($sql);
		$periode = $row[Periode];
	}
	elseif($st == "setuju"){
		$Faction = "../lib/update.php";
		$Vbutton = "Setujui";
		$sql = mssql_query("SELECT CONVERT(CHAR(12), tgl_kwitansi, 103) TglKwitansi, CONVERT(CHAR(12), tanggal, 103) tgl_restitusi, CONVERT(CHAR(12), tgl_bayar, 103) TglBayar, * FROM VMedical WHERE NIK='$nikg' AND nomor='$no_res'",$conn);
		$row = mssql_fetch_array($sql);
		$periode = $row[Periode];
	
	}
	else{
		$Faction 	= "../lib/save.php";
		$Vbutton 	= "Save";
		$sql 		= mssql_query("SELECT * FROM Karyawan WHERE NIK='$nik' ",$conn);
		$row 		= mssql_fetch_array($sql);
	}
 ?>

<script language="javascript" src="../js/urchin.js"></script>
<script language="javascript" src="../js/event.js"></script>
 <script type="text/javascript">
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};
	///////////////////// VALIDASI FORM ////////////////////////////
	function Validate(){
		var F = document.forms[0];
		
		if(F.nik.value == ""){
			alert("Maaf, NIK tidak boleh kosong ... ");
			F.nik.focus();
			return false;
		}
		
		if(F.no_restitusi.value == ""){
			alert("Maaf, Nomor Restitusi tidak boleh kosong ... ");
			F.no_restitusi.focus();
			return false;
		}
		
		if(F.tgl_restitusi.value == ""){
			alert("Maaf, Tanggal Restitusi tidak boleh kosong ... ");
			F.tgl_restitusi.focus();
			return false;
		}

		if(F.tgl_bayar.value == ""){
			alert("Maaf, Tanggal Bayar tidak boleh kosong ... ");
			F.tgl_bayar.focus();
			return false;
		}

		/*if(F.diperiksa_oleh.value == ""){
			alert("Maaf, Field: Diperiksa oleh, tidak boleh kosong ... ");
			F.diperiksa_oleh.focus();
			return false;
		}*/

		if(F.diajukan_oleh.value == ""){
			alert("Maaf, Field: Diajukan oleh,  tidak boleh kosong ... ");
			F.diajukan_oleh.focus();
			return false;
		}
		
		if(F.tgl_kwitansi.value == ""){
			alert("Maaf, Tanggal Kwitansi tidak boleh kosong ... ");
			F.tgl_kwitansi.focus();
			return false;
		}

		if(F.nama_tertanggung.value == ""){
			alert("Maaf, Nama Tertanggung tidak boleh kosong ... ");
			F.nama_tertanggung.focus();
			return false;
		}

		if(F.status_kel_restitusi.value == ""){
			alert("Maaf, Status Keluarga Restitusi tidak boleh kosong ... ");
			F.status_kel_restitusi.focus();
			return false;
		}

		if(F.nama_dokter.value == ""){
			alert("Maaf, Nama Dokter/Rumah Sakit/Apotik/Optik tidak boleh kosong ... ");
			F.nama_dokter.focus();
			return false;
		}

		if(F.mata_anggaran.value == ""){
			alert("Maaf, Mata Anggaran tidak boleh kosong ... ");
			F.mata_anggaran.focus();
			return false;
		}
		
		if(F.cara_bayar.value == ""){
			alert("Maaf, Cara Pembayaran tidak boleh kosong ... ");
			F.cara_bayar.focus();
			return false;
		}

		F.submit();		
	}
 </script>
 <table width="93%" class="table_indent2" cellpadding="0" cellspacing="0">
  <tr>
   <td class="line_bottom">&nbsp;&nbsp; <b>DETAIL MEDICAL KARYAWAN</b></td>
  </tr>
 </table>
 <table style="position:relative; left:80px;" width="91%">
 <tr>
  <td>
<form method="post" action="<?=$Faction?>">
  <table>
   <tr> 
    <td width="150">NIK</td>
	<td><input type="text" name="nik"  value="<?=$row[NIK]?>" readonly="" /></td>
   </tr>
   <tr> 
    <td>Nama</td>
	<td><input type="text" name="nama" size="50" value="<?=$row[Nama]?>" readonly=""  /></td>
   </tr>
   <!--
   <tr>
    <td>Divisi/Biro</td>
	<td>
	 <select name="">
	  <option></option>
	 </select>
	</td>
   </tr>
   <tr>
    <td>Bagian</td>
	<td><input type="text" /></td>
   </tr>
   -->
  </table>
  </td>
 </tr>
 <tr>
  <td><hr noshade="noshade" size="-1" color="#CCCCCC" /></td>
 </tr>
 <tr>
  <td>Periode: <input style="text-align:right;" type="text" maxlength="4" size="5" name="periode" readonly="" value="<?=$periode?>" />  <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>
   <table>
    <tr>
	 <td colspan="3"></td>
	</tr>
    <tr>
	 <td valign="top">
	 <?
	 	// ambil data plafon
		$plaf_KM 		= mssql_query("SELECT * FROM VSetupMedical WHERE NIK='$row[NIK]' AND Periode='$periode'",$conn);
		$row_plaf_KM 	= mssql_fetch_array($plaf_KM);
		$plafon_KM		= $row_plaf_KM[PlafonKacaMata]; // plafon kaca mata
		$plafon_RJ		= $row_plaf_KM[PlafonRawatJalan]; // plafon rawat jalan
		// ambil data plafon yang terpakai
		$pake_plafon	= mssql_query("SELECT SUM(setuju_RJ) jml_rawat_jalan, SUM(setuju_KM) jml_kaca_mata FROM VMedical WHERE NIK='$row[NIK]' AND Periode='$periode' ",$conn);
		$rpake_plafon	= mssql_fetch_array($pake_plafon); // nilai dari plafon yang digunakan
		// sisa plafon 
		$sisa_plaf_KM	= ($plafon_KM-$rpake_plafon[jml_kaca_mata]); // sisa plafon kaca mata
		$sisa_plaf_RJ	= ($plafon_RJ-$rpake_plafon[jml_rawat_jalan]); // sisa plafon rawat jalan
	 ?>
	 <fieldset><legend>Plafon Kaca Mata</legend>
	  <table>
	   <tr>
	    <td>Saldo Awal Plafon</td>
		<td><input type="text" name="plafon_KM_awal" readonly="" value="<?="Rp. ".number_format($plafon_KM)?>" style="text-align:right;"  /></td>
	   </tr>
	   <tr>
	    <td>Jumlah plafon yang terpakai</td>
		<td><input type="text" name="plafon_KM_terpakai" readonly="" value="<?="Rp. ".number_format($rpake_plafon[jml_kaca_mata])?>"  style="text-align:right;" /></td>
	   </tr>
	   <tr>
	    <td>Saldo Akhir Plafon</td>
		<td><input type="text" name="plafon_KM_akhir" readonly="" style="text-align:right;"  value="<?="Rp. ".number_format($sisa_plaf_KM)?>" /></td>
	   </tr>	   
	  </table>
	 </fieldset>
	 </td>
	 <td valign="top">
	 <fieldset><legend>Plafon Rawat Jalan</legend>
	  <table>
	   <tr>
	    <td>Saldo Awal Plafon</td>
		<td><input type="text" name="plafon_RJ_awal" readonly="" value="<?="Rp. ".number_format($plafon_RJ)?>" style="text-align:right;"  /></td>
	   </tr>
	   <tr>
	    <td>Jumlah plafon yang terpakai</td>
		<td><input type="text" name="plafon_RJ_terpakai" readonly="" value="<?="Rp. ".number_format($rpake_plafon[jml_rawat_jalan])?>"  style="text-align:right;" /></td>
	   </tr>
	   <tr>
	    <td>Saldo Akhir Plafon</td>
		<td><input type="text" name="plafon_RJ_akhir" readonly="" style="text-align:right;"  value="<?="Rp. ".number_format($sisa_plaf_RJ)?>" /></td>
	   </tr>	   
	  </table>
	 </fieldset>
	 </td>
	 <td valign="top" rowspan="2">
	 <fieldset><legend>Restitusi</legend>
	  <table>
	   <tr>
	    <td style="font-weight:bold;"><b>No. Resititusi</b></td>
		<td><input type="text" size="18" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> name="no_restitusi" style="font-weight:bold; background-color:#FFF0F8;" value="
		<?
         if($row[nomor] == ""){
			echo date("dmYhms").rand(0,5);
		 }
		 else{
			echo $row[nomor];
		 }
		?>
		"
		<?	
		 if($op == "edit")
		 { 
		 	echo"readonly=''"; 
		 } 
		 else{ 
		 } 
		 ?> /> <span class="required">*</span></td>
	   </tr>
	   <tr>
	    <td style="font-weight:bold;">Tgl. Restitusi</td>
		<td><input type="text" name="tgl_restitusi" style="font-weight:bold; background-color:#FFF0F8;" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> value="<?=$row[tgl_restitusi]?>" maxlength="10" size="11" /> <span class="required">*</span> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> </td>
	   </tr>
	   <tr>
	    <td style="font-weight:bold;">Tgl. Dibayar</td>
		<td><input type="text" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> name="tgl_bayar" style="font-weight:bold; background-color:#FFF0F8;"  value="<?=$row[TglBayar]?>" maxlength="10" size="11" /> <span class="required">*</span> <a href="javascript:calB.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> </td>
	   </tr>	
	   <tr>
	    <td>&nbsp;</td>
	   </tr>	   
	   <tr>
	    <td>Diperiksa Oleh</td>
		<td><input type="text" maxlength="25" name="diperiksa_oleh" value="<?=$row[DiperiksaBy]?>"  <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; }?> /> </td>
	   </tr>  
	   <tr>
	    <td>Diajukan Oleh</td>
		<td><input type="text" maxlength="25" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> name="diajukan_oleh" value="<?
			if($row[DiAjukanBy] == ""){
				echo $row[Nama];
			}
			else{
				echo $row[DiAjukanBy];
			}
		?>
		" readonly="" /> <span class="required">*</span></td>
	   </tr>
	   <tr>
	    <td height="10">&nbsp;</td>
	   </tr>	   
	  </table>
	 </fieldset>
	 </td>
	</tr>
	<tr>
	 <td valign="bottom">
	 <fieldset><legend>Beban Rawat Inap</legend>
	  <table>
	   <tr>
	    <td>Beban Perusahaan</td>
		<td><input name="beban_RI_prsh" type="text" value="<?=$row[RI_Prsh]?>" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; }?> style="text-align:right;" /></td>
	   </tr>
	   <tr>
	    <td>Beban Pegawai</td>
		<td><input name="beban_RI_kar" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; } ?> type="text" value="<?=$row[RI_Kar]?>"  style="text-align:right;" /></td>
	   </tr>
	  </table>
	 </fieldset>
	 </td>
	 <td valign="bottom">
	 <fieldset><legend>Beban Persalinan</legend>
	  <table>
	   <tr>
	    <td>Beban Perusahaan</td>
		<td><input name="beban_PR_prsh" value="<?=$row[RP_Prsh]?>" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; } ?> type="text"  style="text-align:right;" /></td>
	   </tr>
	   <tr>
	    <td>Beban Pegawai</td>
		<td><input name="beban_PR_kar" value="<?=$row[RP_Kar]?>" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; } ?> type="text"  style="text-align:right;" /></td>
	   </tr>
	  </table>
	 </fieldset>
	 </td>
	</tr>
   </table>
  </td>
 </tr>
 <tr>
  <td>
  <fieldset>
  <legend><b>Detail Restitusi</b></legend>
  <table width="100%">
  <tr>
  <td>
   <table>
   <tr>
    <td>Tgl. Kwitansi</td>
	<td><input type="text" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";} ?> name="tgl_kwitansi" value="<?=$row[TglKwitansi]?>"  maxlength="10" size="11" /> <span class="required">*</span> <a href="javascript:calC.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> </td>
   </tr>
   <tr>
    <td>Nama Tertanggung</td>
	<td><input type="text" maxlength="25" name="nama_tertanggung" value="<?=$row[nama_tertanggung]?>" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> /><span class="required">*</span></td>
   </tr>
   <tr>
    <td>Status Keluarga</td>
	<td>
	 <select name="status_kel_restitusi" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?>>
	  <?
	   // get status selected
	   $sSKRa = mssql_query("SELECT * FROM VHubKelRes WHERE kode='$row[status_kel]'",$conn);
	   $rSKRa = mssql_fetch_array($sSKRa);
	   echo"<option value='$rSKRa[kode]'>$rSKRa[nama]</option>";
	  ?>
	  <option value="">--pilih</option>
	  <?
	  	// SKR --> Status Keluarga Restitusi
	  	$sSKR = mssql_query("SELECT * FROM VHubKelRes ORDER BY kode ASC",$conn);
		while($rSKR = mssql_fetch_array($sSKR)){
			echo"<option value='$rSKR[kode]'>$rSKR[nama]</option>";
		}
	  ?>
	 </select>
	</td>
   </tr>
   <tr>
    <td>Nama Dokter/Rumah Sakit/<br />Apotik/Optik<br /><br /></td>
	<td><input <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> type="text" maxlength="25" name="nama_dokter" value="<?=$row[nama_dokter]?>"  /><span class="required">*</span><br /><br /></td>
   </tr>
   <tr>
    <td>Kode/Nama Mata Anggaran</td>
	<td>
	<select name="mata_anggaran" style="width:100px;" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?>>
	 <?
	 	// get mata anggaran selected
		$gMA	= mssql_query("SELECT * FROM MedicalMataAnggaran WHERE mata_anggaran='$row[mata_anggaran]'",$conn);
		$hMA	= mssql_fetch_array($gMA);
		echo"<option value='$hMA[mata_anggaran]'>$hMA[mata_anggaran] - $hMA[uraian]</option>";
	 ?>
	 <option value="">--pilih--</option>
	 <?
	 	// get mata anggaran
	 	$sMA	= mssql_query("SELECT * FROM MedicalMataAnggaran ORDER BY mata_anggaran",$conn);
		while($rMA = mssql_fetch_array($sMA)){
			echo"<option value='$rMA[mata_anggaran]'>$rMA[mata_anggaran] - $rMA[uraian]</option>";
		}
	 ?>
	</select><span class="required">*</span>
	</td>
   </tr>
   <tr>
    <td>Cara Bayar</td>
	<td>
	 <select name="cara_bayar" <? if($op == "edit") {} elseif($st == "setuju") {echo"readonly";}?> >
	  <?
	  	// get cara bayar selected
		$gCB = mssql_query("SELECT * FROM VCaraBayar WHERE kode='$row[cara_bayar]'",$conn);
		$hCB = mssql_fetch_array($gCB);
		echo"<option value='$hCB[kode]'>$hCB[nama]</option>";
	  ?>
	  <option value="" style="width:105px;">--pilih--</option>
	  <?
	  	$sCB = mssql_query("SELECT * FROM VCaraBayar ORDER BY kode",$conn);
		while($rCB = mssql_fetch_array($sCB)){
			echo"<option value='$rCB[kode]'>$rCB[nama]</option>";
		}
	  ?>
	 </select><span class="required">*</span>
	</td>
   </tr>
   </table>
   </td>
   <td valign="top">
    <table width="100%" border="0" cellpadding="2">
	 <tr class="headlist">
	  <td align="left">Total/Jenis Restitusi</td>
	  <td>Rawat Jalan</td>
	  <td>Kaca Mata</td>
	  <td>Rawat Inap</td>
	 </tr>
	 <tr class="contentlist">
	  <td>Total Jumlah Yang Diajukan</td>
	  <td><input type="text" name="klaim_RJ" style="text-align:right; background-color:#FFF0F8;" value="<?=$row[klaim_RJ]?>" id="pengajuan rawat jalan" <? if($op == "edit") {} elseif($st == "setuju") { echo"readonly";}?> /></td>
	  <td><input type="text" name="klaim_KM" style="text-align:right; background-color:#FFF0F8;" value="<?=$row[klaim_KM]?>" id="pengajuan kaca mata" <? if($op == "edit") {} elseif($st == "setuju") { echo"readonly";}?> /></td>
	  <td><input type="text" name="klaim_RI" style="text-align:right; background-color:#FFF0F8;" value="<?=$row[klaim_RI]?>" id="pengajuan rawat inap" <? if($op == "edit") {} elseif($st == "setuju") { echo"readonly";}?> /></td>
	 </tr>
	 <tr class="contentlist">
	  <td>Total Jumlah Yang Disetujui</td>
	  <td><input type="text" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; }?> name="setuju_RJ" style="text-align:right; background-color:#FFF0F8;" value="<?=$row[setuju_RJ]?>" id="disetujui rawat jalan" /></td>
	  <td><input type="text" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; }?> name="setuju_KM" style="text-align:right; background-color:#FFF0F8;" value="<?=$row[setuju_KM]?>" id="disetujui kaca mata" /></td>
	  <td><!--<input type="text" <? if($op == "edit") {echo"readonly";} elseif($st == "setuju") {} else { echo"readonly"; }?> name="setuju_RI" style="text-align:right; background-color:#FFF0F8;" value="<?=$row[setuju_RI]?>" id="disetujui rawat inap" />--></td>
	 </tr>
	</table>
	<br />
	<br />
	<div align="right">
		<input type="hidden" name="cat" <? if($op == "edit") {echo'value="medical"';} elseif($st == "setuju") { echo'value="medical_setuju"';} else { echo"value='medical'"; }?> />
		<input type="button" class="button" value="Cancel" onclick="Javascript:history.back();" />
		<input type="button" class="button" value="<?=$Vbutton?>" onclick="Javascript:Validate();" />
	</div>
   </td>
   </tr>
  </table>
  </fieldset>
  </form>
  </td>
 </tr>
</table>
</body>
</html>
<script type="text/javascript">
<?
//	if($show == ""){
?>
/*
var f = document.forms[0];
MaskInput(f.tgl_restitusi,"99/99/9999");
MaskInput(f.tgl_bayar,"99/99/9999");
MaskInput(f.tgl_kwitansi,"99/99/9999");
MaskInput(f.beban_RI_prsh,"9999999999999999");
MaskInput(f.beban_RI_kar,"9999999999999999");
MaskInput(f.beban_PR_prsh,"9999999999999999");
MaskInput(f.beban_PR_kar,"9999999999999999");  
MaskInput(f.klaim_RJ,"9999999999999999");
MaskInput(f.klaim_RI,"9999999999999999");
MaskInput(f.klaim_KM,"9999999999999999");
MaskInput(f.setuju_RJ,"9999999999999999");
MaskInput(f.setuju_RI,"9999999999999999");
MaskInput(f.setuju_KM,"9999999999999999");
*/
<?
	//}
?>
</script>
<script type="text/javascript">
// script untuk popup calendar
	var calA = new calendar1(document.forms[0].elements['tgl_restitusi']);
	calA.year_scroll = true;
	calA.time_comp = false;	
	var calB = new calendar1(document.forms[0].elements['tgl_bayar']);
	calB.year_scroll = true;
	calB.time_comp = false;	
	var calC = new calendar1(document.forms[0].elements['tgl_kwitansi']);
	calC.year_scroll = true;
	calC.time_comp = false;	
</script>
